package com.gzhu.knowledgeAdmin.controller;

import com.gzhu.knowledgeAdmin.common.result.R;
import com.gzhu.knowledgeAdmin.common.valid.AddGroup;
import com.gzhu.knowledgeAdmin.common.valid.UpdateGroup;
import com.gzhu.knowledgeAdmin.common.vo.ConditionVo;
import com.gzhu.knowledgeAdmin.common.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.gzhu.knowledgeAdmin.entity.Condition;
import com.gzhu.knowledgeAdmin.service.ConditionService;

import java.util.Map;
import java.util.List;

/**
 * 条件表
 *
 * @author yangminggui
 * @email giaogiao@gmail.com
 * @date 2024-01-25 23:16:07
 */
@RestController
@RequestMapping("knowledgeAdmin/condition")
public class ConditionController {
    @Autowired
    private ConditionService conditionService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageVo page = conditionService.queryPage(params);
        return R.ok(page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
        ConditionVo conditionVo = conditionService.getConditionById(id);
        return R.ok(conditionVo);
    }

    /**
     * 添加
     */
    @PostMapping("/save")
    public R save(@RequestBody @Validated(AddGroup.class) Condition condition){
		ConditionVo conditionVo = conditionService.saveOrUpdateCondtion(condition);
        return R.ok(conditionVo);
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody @Validated(UpdateGroup.class) Condition condition){
        ConditionVo conditionVo  =  conditionService.saveOrUpdateCondtion(condition);
        return R.ok(conditionVo);
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody List<Integer> ids){
		conditionService.removeConditionByIds(ids);
        return R.ok();
    }

}
